﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace A6
{
    public partial class query: Form
    {
        private OrderService orderService;
        public delegate void SearchCompletedHandler(List<Order> results);
        public SearchCompletedHandler OnSearchCompleted;
        public query(OrderService _orderService)
        {
            InitializeComponent();
            orderService = _orderService;
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                // 执行查询
                string key = comboBox1.Text;
                List<Order> results = new List<Order>();
                if(key == "订单号")
                {
                    results = orderService.QueryID(Int32.Parse(textBox1.Text));
                }
                else if(key == "商品名称")
                {
                    results = orderService.QueryName(textBox1.Text);
                }
                else if(key == "金额")
                {
                    results = orderService.QueryMoney(double.Parse(textBox1.Text));
                }
                else if(key == "客户名称")
                {
                    results = orderService.QueryGuest(textBox1.Text);
                }
                if (OnSearchCompleted != null)
                {
                    OnSearchCompleted(results); // 触发回调
                }
                this.Close(); // 关闭查询窗口
            }
            catch (Exception ex)
            {
                MessageBox.Show($"查询失败: {ex.Message}");
            }
        }
    }
}
